package galleryviewer;

import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.scene.image.*;

import galleryviewer.data.DataLoader;
import galleryviewer.data.LocalBean;


/**
 * @author SiMet
 */

public class Window extends Group{
    
    public var jakDojscButton : Boolean = true;
    public var clickX : Number;
    public var clickY : Number;
    public var wysokosc : Number = Constants.FRAME_HEIGHT -200;
    public var szerokosc : Number = Constants.FRAME_WIDTH -200;
    public var tresc : Group;
    public var localId : Number;
    override var blocksMouse = true;
    var localBean : LocalBean;
        
    init
    {

        var darkenBG = Rectangle {

            x: 0,
            y: 0,
            width: Main.stage.width,
            height: Main.stage.height,
            arcWidth: 0, arcHeight: 0
            fill: Color.web("#232122"),
            opacity: 0.95;
        }
        var box = Rectangle{
            x: (0),
            y: (0),
            width: szerokosc, height: wysokosc,
            arcWidth: 50, arcHeight: 50
            fill: Color.web("#ffffff"),
            strokeWidth : 0;
        }

    var powrot : ImageView = ImageView{
       image: Image {url: "{__DIR__}img/powrot.png" backgroundLoading: true}
       x: szerokosc-250 y: wysokosc-100;
       onMouseClicked: function(ev:MouseEvent){
           	Effects.fadeOut(Main.currentlyOpenedWindow);
       }
   }
   var jakdojsc : ImageView =ImageView{
       image: Image {url: "{__DIR__}img/droga.png" backgroundLoading: true}
       x: szerokosc-475 y: wysokosc-100;
       onMouseClicked: function(ev:MouseEvent){
			Effects.fadeOut(this);
            function_jakdojsc();
       }
   }

   var windowBox : Group = Group {

            content: [
                    box, tresc, powrot,
                    ];

                    onMouseClicked : function(ev: MouseEvent){
                        Main.globalCounter.stop();
	                Main.globalCounter.playFromStart();
	              }


            translateX : (Constants.FRAME_WIDTH/2 - szerokosc/2);
            translateY : (Constants.FRAME_HEIGHT/2 - wysokosc/2);

        }
        if(jakDojscButton)
            insert jakdojsc into windowBox.content;

        insert darkenBG into content;
	    insert windowBox into content;
    }
    public function close(){
        delete content;
    }
    public function function_jakdojsc(){
        
        PopUp.closePopups(null);
        var currentPosPopup : PopUp = PopUp{text: "Jestes tutaj",szerokosc:150,wysokosc:40, clickX : 65, clickY : 160, maxX : GalleryFloor.floors[0].galleryFloorWidth, maxY : scene.height};
        var destinationPopup : PopUp = PopUp{text: "Tu chcesz dotrzec",szerokosc:150,wysokosc:40, clickX : clickX, clickY : clickY, maxX : GalleryFloor.floors[GalleryFloor.currentFloor].galleryFloorWidth, maxY : scene.height};
        var stairsUpPopup : PopUp = PopUp{
            text: "Wyjdz na gore"
            szerokosc:150
            wysokosc:40
            clickX : 370
            clickY : 100
            maxX : GalleryFloor.floors[0].galleryFloorWidth
            maxY : scene.height
            onMouseClicked : GalleryFloor.displayedFloorIncrement;
        };
         var stairsDownPopup : PopUp = PopUp{
                              text: "Wyjdziesz tutaj"
                              szerokosc:150
                              wysokosc:40
                              clickX : 370
                              clickY : 100
                              maxX : GalleryFloor.floors[GalleryFloor.currentFloor].galleryFloorWidth
                              maxY : scene.height
                          };                 
        
        insert currentPosPopup into GalleryFloor.openedPopups;
        insert destinationPopup into GalleryFloor.openedPopups;
       
        
        insert currentPosPopup into GalleryFloor.floors[0].galleryContent;
        insert destinationPopup into GalleryFloor.floors[GalleryFloor.currentFloor].galleryContent;
        
        if(GalleryFloor.currentFloor != 0){
            
            insert stairsUpPopup into GalleryFloor.openedPopups;
            insert stairsUpPopup into GalleryFloor.floors[0].galleryContent;
            
            insert stairsDownPopup into GalleryFloor.openedPopups;
            insert stairsDownPopup into GalleryFloor.floors[GalleryFloor.currentFloor].galleryContent;
            
            GalleryFloor.currentFloor = 0;           
        }
    }
}
